package com.jpa.element.collections.mappings.tutorial;

import com.jpa.element.collections.mappings.tutorial.domain.Artist;
import com.jpa.element.collections.mappings.tutorial.domain.Event;
import com.jpa.element.collections.mappings.tutorial.service.ArtistService;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

public class JpaElementCollectionsMappingsTutorial {

    public static void main(String[] args) {
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("JpaElementCollectionsMappingsTutorial");
        EntityManager em = emf.createEntityManager();
        ArtistService service = new ArtistService(em);

        System.out.println("--- Find artist ---");
        Artist artist = service.findArtist(1);
        System.out.println(String.format("Found: %s", artist));

        System.out.println("\nArtist aliases:");
        for (String alias : artist.getAliases()) {
            System.out.println(alias);
        }

        System.out.println("\nArtist events:");
        for (Event event : artist.getEvents()) {
            System.out.println(event);
        }

        em.close();
        emf.close();
    }
}
